/*
 * @Descripttion: 
 * @version: 请写项目版本
 * @Author: @cdm
 * @Date: 2021-09-08 13:54:32
 * @LastEditors: @cdm
 * @LastEditTime: 2021-12-20 14:16:21
 * No pains no gains
 */
import { game } from "../../../../../script/game/control/game";
import { companyBase } from "../../../../../script/game/control/Item/ItemBase";
import { companyType } from "../../../../../script/game/gameType";
import { ListItem } from "../../../../../script/util/ListView/ListItem";
import { ccs } from "../../../../../script/util/services";
import { TouchExtend } from "../../../../../script/util/TouchExd";
import { touchExd } from "../../../../../script/util/TouchExtend";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends ListItem<companyType> {
    

    @property(cc.Label)
    title: cc.Label = null;

    @property(cc.Label)
    desc: cc.Label = null;

    @property(cc.Label)
    workers: cc.Label = null;

    @property(cc.Label)
    income: cc.Label = null;

    @property(cc.Label)
    pay: cc.Label = null;

    @property(cc.Label)
    power: cc.Label = null;

    @property(cc.Label)
    year: cc.Label = null;

    @property(cc.Node)
    have: cc.Node = null;

    @property(cc.Node)
    mask: cc.Node = null;

    @property(cc.Node)
    inverst: cc.Node = null;

    @property(cc.Node)
    icon: cc.Node = null;
    start () {

    }

    initItem(data: companyType, index: number) {
        ccs.spriteExd.setSprite(this.icon, ccs.resMgr.getCompanyIcon(data.skill));
        let item: companyBase = game.playerMgr.bag.companyBag.getItem(data.id);
        if(item) {
            this.title.string = item.company.name + "";
            this.workers.string = "员工：" + ccs.gf.getOmitNum(item.company.workers) + "/" + ccs.gf.getOmitNum(item.company.maxWorker) + "人";
            this.year.string = data.year + "";
            // this.have.active = true; 
            this.mask.active = false; 
            this.inverst.active = false; 
            this.income.string = `营收: ${ccs.gf.getOmitNum(item.company.incomeMonth)}`;
            this.pay.string = `支出：${ccs.gf.getOmitNum(item.company.payMonth)}`;
            this.power.string = "资金：" + ccs.gf.getOmitNum(item.company.money);
        } else {
            this.title.string = data.name;
            // this.have.active = false;
            this.workers.string = ccs.gf.getOmitNum(data.inverst);
            this.workers.string = '员工：--';
            this.income.string = '营收：--';
            this.mask.active = true;
            this.inverst.active = true;
            this.pay.string = '支出：--';
            this.power.string = "资金：" + ccs.gf.getOmitNum(data.money);
        }
        TouchExtend.touchEndScale(this.inverst, () => {
            ccs.winMgr.showWin("popAlert", {content: "投资需花费" + ccs.gf.getOmitNum(data.inverst) + "元", cb: () => {
                game.playerMgr.inverst(data);
                ccs.mainEmitter.emit("upCompany");
            }})
        })

    }
    onItemclick(data: companyType) {
        //跳转详情页面
        ccs.winMgr.showWin("popCompanyWin", {id: data.id});
    }
    // update (dt) {}
}
